package cn.net.mugui.net.pc;

import java.io.PrintStream;
import java.security.Security;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.bouncycastle.jce.provider.BouncyCastleProvider;

import com.mugui.base.base.ApplicationContext;
import com.mugui.base.client.net.baghandle.NetBagModuleManager;
import com.mugui.base.client.net.classutil.DataSave;
import com.mugui.sql.DBConf;

import cn.net.mugui.net.pc.panel.BilibiliPanel;

/**
 * Hello world!
 *
 */
public class PcBilibiliApp {
	static {
		Security.addProvider(new BouncyCastleProvider());
	}
	public static void main(String[] args) {
		LogInit();
		DataSave.APP_PATH(PcBilibiliApp.class);
		DBConf.getDefaultDBConf().readConf("org.sqlite.JDBC", "jdbc:sqlite:" + DataSave.APP_PATH + "//mugui.dll",
				"root", "mugui123");
		DataSave.context = new ApplicationContext();
		DataSave.context.init("cn.net.mugui", "com.mugui");
		DataSave.context.getBean(NetBagModuleManager.class).init(PcBilibiliApp.class);
		System.out.println(DataSave.APP_PATH);
		try {
			AppFrame bean = DataSave.context.getBean(AppFrame.class);
			bean.init();
			bean.setVisible(true);
			bean.updateUI(DataSave.context.getBean(BilibiliPanel.class));
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(-1);
		}
	}
	
	 /**
		 * 日志系统初始化
		 * 
		 * @param args
		 */
		private static  void LogInit() {
			PrintStream out = new PrintStream(System.out) {
				DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");

				@Override
				public void print(String s) {
					super.print(
							format.format(new Date()) + ":\t" + "Thread:" + Thread.currentThread().getName() + "    :" + s);
				}

				@Override
				public void println(String x) {
					print(x + "\r\n");
				}

				@Override
				public void print(Object obj) {
					print(String.valueOf(obj));
				}

				@Override
				public void println(Object x) {
					println(String.valueOf(x));
				}

				@Override
				public void print(char c) {
					print(String.valueOf(c));
				}

				@Override
				public void print(boolean b) {
					print(String.valueOf(b));
				}

				@Override
				public void print(float f) {
					print(String.valueOf(f));
				}

				@Override
				public void print(int i) {
					print(String.valueOf(i));
				}

				@Override
				public void println(char c) {
					println(String.valueOf(c));
				}

				@Override
				public void println(boolean b) {
					println(String.valueOf(b));
				}

				@Override
				public void println(float f) {
					println(String.valueOf(f));
				}

				@Override
				public void println(int i) {
					println(String.valueOf(i));
				}
			};
			System.setOut(out);
		}
}
